package com.itheima.thread;

public class Synochronizedd implements Runnable {
    private int tickets = 100;
    int i=0;
    @Override
    public void run() {
        while (true) {
            selltickets();
        }
    }

    private synchronized void selltickets() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (tickets > 0) {
            System.out.println( Thread.currentThread().getName()+"出售第"+i+"张票");
            i--;
            tickets--;
        }
    }
}

class Tet {
    public static void main(String[] args) throws InterruptedException {
        Synochronizedd v = new Synochronizedd();
        Thread thread1 = new Thread(v, "一号窗口");
        Thread thread2 = new Thread(v, "二号窗口");
        Thread thread3 = new Thread(v, "三号窗口");
//        thread1.sleep(1000);
//        thread1.sleep(1000);
//        thread1.sleep(1000);1000
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
